﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DAL;
using BLL;
namespace PhongMachTu.GUI
{
    public partial class frmSuaBenhNhan : Form
    {
        public frmSuaBenhNhan()
        {
            InitializeComponent();
        }

        private void btnThoat_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        public event EventHandler Button_Clicked;
        public int maBenhNhan;
        KhambenhBLL bllKB = new KhambenhBLL();
        private void btnLuuVaThem_Click(object sender, EventArgs e)
        {
            if (MsgBox.checkNull(txtTenBN))
            {
                return;
            }
            if (MsgBox.checkNull(txtDiaChi))
            {
                return;
            }
            BENHNHAN bn = new BENHNHAN();
            bn.MaBenhNhan = maBenhNhan;
            bn.HoTen = txtTenBN.Text;
            bn.NgaySinh = dtNgaySinh.Value;
            bn.DiaChi = txtDiaChi.Text;
            bn.GioiTinh = rbtNam.Checked ? true : false;
            BenhNhanBLL bllBN = new BenhNhanBLL();
            bllBN.suaBenhNhan(bn);
            if (this.Button_Clicked != null)
                this.Button_Clicked(sender, e);
      

        }

        private void frmSuaBenhNhan_Load(object sender, EventArgs e)
        {
            try
            {
                BenhNhanBLL bllBN = new BenhNhanBLL();
                foreach (var item in bllBN.LayDSBenhNhan(maBenhNhan))
                {
                    txtTenBN.Text = item.HoTen;
                    txtDiaChi.Text = item.DiaChi;
                    dtNgaySinh.Value = item.NgaySinh.Value;
                    if (item.GioiTinh.ToString() == "Nam")
                    {
                        rbtNam.Checked = true;
                    }
                    else
                    {
                        rbtNu.Checked = false;
                    }
                }
            }
            catch
            {


            }

        }

        private void btnLuu_Click(object sender, EventArgs e)
        {
            if (MsgBox.checkNull(txtTenBN))
            {
                return;
            }
            if (MsgBox.checkNull(txtDiaChi))
            {
                return;
            }
            BENHNHAN bn = new BENHNHAN();
            bn.MaBenhNhan = maBenhNhan;
            bn.HoTen = txtTenBN.Text;
            bn.NgaySinh = dtNgaySinh.Value;
            bn.DiaChi = txtDiaChi.Text;
            bn.GioiTinh = rbtNam.Checked ? true : false;
            BenhNhanBLL bllBN = new BenhNhanBLL();
            if (bllBN.suaBenhNhan(bn))
            {
                if (this.Button_Clicked != null)
                    this.Button_Clicked(sender, e);
                this.Close();

            }
            else
            {
                MsgBox.Error("Xảy ra lỗi !");
            }
        }
    }
}
